<template>
	<view class="billdetails">
		<view class="billdetails_top">
			<view class="name">{{name}}{{address}}</view>
			<view class="moeny">{{Number(billList.allMoney).toFixed(2)}}</view>
			<view class="last">{{code == 0 ? '已缴费':'未缴费'}}</view>
		</view>
		<!-- 分割线 -->
		<view class="xian ">
			<view class="xian_left"></view>
			<view class="xian_center"></view>
			<view class="xian_right"></view>
		</view>
		<!-- 主体内容 -->
		<view class="main">
			<view class="main_jh">
				<view class="zdbh clearfix">
					<view class="bh">账单编号</view>
					<view class="num">{{billList.code}}</view>
				</view>
				<!-- <view class="zdbh clearfix" v-show="billList.order.status==1">
					<view class="bh">截止时间</view>
					<view class="num">{{num}}</view>
				</view> -->
			</view>
			<view class="wyf">
				<view v-for="(item,index) in billList.costList" :key='index' class="clearfix view">
					<view class="u-font-32 u-m-b-20">
						{{item.startTime}}~{{item.endTime}}
					</view>
					<view class="wyfname">{{billList.type=="1"?"水费":"电费"}}</view>
				
					<view class="wyfmoney">{{item.Due}}</view>
				</view>
			</view>
			<!-- <view class="main_jh">
				<view class="zdbh clearfix" v-show="billList.order.status==2">
					<view class="bh">缴费时间</view>
					<view class="num">{{num}}</view>
				</view>
			</view>
			<view class="zdbh clearfix" v-show="billList.order.status==2">
				<view class="bh">支付方式</view>
				<view class="num">{{num}}</view>
			</view>
			<view class="zdbh clearfix" v-show="billList.order.status==2">
				<view class="bh">交易单号</view>
				<view class="num">{{num}}</view>
			</view>
			<view class="zdbh clearfix" v-show="billList.order.status==2">
				<view class="bh">支付人</view>
				<view class="num">{{num}}</view>
			</view> -->
			<view class="u-p-r-40 u-p-l-40 bill-deta-btn" >
				<u-button @click="payClick" v-show="code != 0" type="warning">微信缴费</u-button>
				<br>
				<u-button @click="requestPayment" v-show="code != 0" type="warning">支付宝缴费</u-button>
			</view>
			<!-- <view class="u-p-r-40 u-p-l-40 bill-deta-btn" v-show="code!= 0">
				<button @click="payClick"  type="warning">微信缴费</button>
			</view>
			<view class="u-p-r-40 u-p-l-40 bill-deta-btn" v-show="code!= 0">
				<button @click="requestPayment"  type="warning">支付宝缴费</button>
			</view> -->
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				tableInfo:{},
				allmoney: '3600.00',
				type: '已支付',
				num: 'WY20200807',
				billList: {},
				homelist: '',
				name: '',
				address: '',
				money: '',
				chooseList:[],
				code:-1,
			}
		},
		onNavigationBarButtonTap(e) {
			console.log("success")
			uni.navigateTo({
				url:'/homePage1/pay/pay'
			})
		},
		onLoad(option) {
			this.billList = JSON.parse(option.val)
			this.tableInfo=JSON.parse(option.val2)
			this.homelist = uni.getStorageSync('hourseList')[uni.getStorageSync('hourseNum') || 0]
			this.name = this.homelist.proName;
			this.address = this.homelist.buildDistrictCode + '-' + this.homelist.buildTowerCode + '-' + this.homelist.roomUnitNumber +
					'-' + this.homelist.roomCode
		},
		onShow() {

		this.selectCostState();

		},
		onBackPress(e){
			console.log("监听返回按钮事件",e);
			var item2 = JSON.stringify(this.tableInfo);
			uni.navigateTo({
				url:"/homePage1/forwater/forWaterPay?val="+item2
			})
			return true;
		},
		methods: {
			//缴费状态查询
			selectCostState(){
				this.$request.api.selectCostState({
					code:this.billList.code,
					
				}).then(res => {
					this.code = res.data.code
				})
			},
			//支付宝支付
			requestPayment(){
				// 打开支付宝里面的搜索：  alipayqr://platformapi/startapp?saId=20001003
				// 支付宝收款码:   alipayqr://platformapi/startapp?saId=20000123
				// 支付宝扫一扫：alipayqr://platformapi/startapp?saId=10000007
				// 支付宝付款：alipay://platformapi/startapp?appId=20000056
				//let authUrl = `alipays://platformapi/startapp?appId=20000067&url=HTTPS%3a%2f%2fQR.ALIPAY.COM%2fFKX09099VQZDCJ1QFGXA9F`;
				//let authUrl = `alipays://platformapi/startapp?appId=2021002127637334&url=${encodeURIComponent('345%^4567657path:009')}`;
				//const query = encodeURIComponent('要带的参数')
				//plus.runtime.openURL("alipays://platformapi/startapp?appId=要跳转的支付宝小程序appid&要跳转的页面" + 要带的参数);
				//const URL = encodeURIComponent('https://www.515f.com/adapay?key=WY2022031919171531&money=0.30&proId=54')
				const order = this.billList.code;//订单编号
				const money = Number(this.billList.allMoney).toFixed(2); //金额
				const proId = this.billList.pro_id;
				const URL = encodeURIComponent(`https://www.515f.com/adapay?key=${order}&money=${money}&proId=${proId}`);
				let authUrl = `alipays://platformapi/startapp?saId=10000007&qrcode=`+URL;
				//console.log(authUrl);
				plus.runtime.openURL(authUrl, function (res) {
					uni.showToast({
						icon: "none",
						title: "请安装支付宝之后再进行支付！",
					});
				});
			},

			//水电
			async payClick() {
				let data = {
					billList:  this.billList,
					tableInfo: this.tableInfo,
					name: this.name,
					address: this.address,

				}
				let str = JSON.stringify(data)
				// 小程序跳转
				plus.share.getServices(
						res => {
							let sweixin = null;
							for (let i in res) {
								if (res[i].id == 'weixin') {
									sweixin = res[i];
								}
							}
							//唤醒微信小程序
							if (sweixin) {
								sweixin.launchMiniProgram({
									id: 'gh_356131c8d206', //
									type: 2, //小程序版本  0-正式版； 1-测试版； 2-体验版。
									path: '/homePage1/forwater/billdetails?data='+str //小程序的页面,用传的参数在小程序接值判断跳转指定页面
								});
							}
							console.log(str)
						}
				);
			}
		}
	}
</script>

<style scoped lang="scss">
	page {
		background-color: rgb(244, 244, 244);

	}

	.billdetails {
		padding: 0 30rpx;
	}

	.billdetails_top {
		height: 312rpx;
		text-align: center;
		background-color: #fff;
		margin-top: 60rpx;
		border-top-left-radius: 6px;
		border-top-right-radius: 6px;

		.name {
			padding-top: 60rpx;
			box-sizing: border-box;

		}

		.last {
			margin-top: 20rpx;
			color: rgb(128, 229, 255);
		}

		.moeny {
			font-size: 48rpx;
			color: #000;
			font-weight: bold;
			margin-top: 60rpx;
		}
	}

	.xian {
		height: 50rpx;
		background-color: #fff;
		display: flex;
		justify-content: space-between;

		.xian_center {
			height: 1px;
			border-top: 1px dashed #ccc;
			margin: 25rpx 40rpx;
			width: 600rpx;

		}

		.xian_left {
			width: 50rpx;
			height: 50rpx;
			border-radius: 50%;
			float: left;
			background-color: rgb(244, 244, 244);
			margin-left: -8vw;
		}
		.xian_right {
			width: 50rpx;
			height: 50rpx;
			border-radius: 50%;
			float: right;
			background-color: rgb(244, 244, 244);
			margin-right: -8vw;

		}
	}

	.zdbh {
		margin-bottom: 30rpx;

		.bh {
			float: left;
		}

		.num {
			float: right;
			
		}
	}

	.wyf {
		.wyfname {
			float: left;
		}

		.wyfmoney {
			float: right;
		}

		.view {
			margin-bottom: 30rpx;
		}
	}

	.main_jh {
		margin-bottom: 60rpx;
	}

	.main {
		background-color: #fff;
		padding: 60rpx 20rpx;
	}

	.bill-deta-btn {
		width: 100%;
		height: 180rpx;
	}
</style>
